class StaffsController < ApplicationController
   before_action :set_menu

  def index
    @submenu = :staff_list
    @title = '员工管理'
    @staffs = Staff.all
  end

  def new
    @staff = Staff.new
  end

  def create
    @staff = Staff.new post_params
    if @staff.save
      redirect_to staffs_path
    else
      render :action => 'new'
    end
  end

  def edit
    @staff = Staff.find params[:id]
  end

  def update
    @staff = Staff.find params[:id]
    if @staff.update_attributes post_params
      redirect_to staffs_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @staff = Staff.find params[:id]
    @staff.destroy
    redirect_to staffs_path
  end


  def post_params
    params.require(:staff).permit(*%w(name phone sex))
  end

  private
  def set_menu
    @mainmenu = :people
  end
end
